/** \file MACD_t.cc 
 * Test definitions for MACD functions.
 *
 * (C) Copyright by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: MACD_t.cc 110 2006-06-19 03:38:33Z semihc $
 *
 *
 */


#include "MACD.hpp"
#include <vector>
#include "TestHarness.hh"

using namespace std;
using namespace TC;



namespace {

  const unsigned DataSize = 55;

  const double macd_data[DataSize] = {
    63.750, 63.625, 63.000, 62.750, 63.250, 65.375, 66.000, 65.000,
    64.875, 64.750, 64.375, 64.375, 64.625, 64.375, 64.500, 65.250,
    67.875, 68.000, 66.875, 66.250, 65.875, 66.000, 65.875, 64.750,
    63.000, 63.375, 63.375, 63.375, 63.875, 65.500, 63.250, 60.750,
    57.250, 59.125, 59.250, 58.500, 59.125, 59.750, 60.625, 60.500,
    59.000, 59.500, 58.875, 59.625, 59.875, 59.750, 59.625, 59.250,
    58.875, 59.125, 60.875, 60.750, 61.125, 62.500, 63.250 };

  const double macd_expect[DataSize] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0.069, -0.057, -0.155, -0.193, -0.099, -0.193, -0.452, -0.913,
    -1.125, -1.269, -1.424, -1.484, -1.467, -1.371, -1.290, -1.325,
    -1.299, -1.311, -1.250, -1.169, -1.101, -1.045, -1.017, -1.012,
    -0.978, -0.809, -0.676, -0.536, -0.317, -0.085 };

}


TEST(MACDTest, Base)
{
     vector<double> result;

     result.clear();
     MACD(macd_data, macd_data+DataSize, 
          back_inserter(result), 
          12, 26, ArrayAdaptor<double>());
     TC_TEST(result.size()==DataSize);
     PrintElements(result, "MACD-period");

     result.clear();
     MACDPct(macd_data, macd_data+DataSize,
             back_inserter(result), 
             0.15, 0.075, ArrayAdaptor<double>());
     TC_TEST(result.size()==DataSize);
     for(unsigned i=0; i<DataSize; ++i)
       if(macd_expect[i] > 0)
         TC_TESTFP(macd_expect[i], result[i]);
     PrintElements(result, "MACD-percent");

}


  



